package top.itmeans.yes.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.itmeans.yes.common.api.CommonResult;
import top.itmeans.yes.entity.OrderSetting;
import top.itmeans.yes.service.OrderSettingService;

/**
 * <p>
 * 订单设置表 前端控制器 OMS
 * </p>
 *
 * @author Yiming.Cao
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * GET [host:ip/serverPath]/orderSetting/{id}
     */
    @ApiOperation("获取指定订单设置")
    @GetMapping("/{id}")
    public CommonResult<OrderSetting> getItem(@PathVariable Long id) {
        OrderSetting orderSetting = orderSettingService.getById(id);
        return CommonResult.success(orderSetting);
    }

    /**
     * Post [host:ip/serverPath]/orderSetting/{id}
     */
    @ApiOperation("修改指定订单设置")
    @PostMapping("/{id}")
    public CommonResult<Boolean> update(@PathVariable Long id, @RequestBody OrderSetting orderSetting) {
        orderSetting.setId(id);
        boolean flag = orderSettingService.updateById(orderSetting);
        return flag ? CommonResult.success(true) : CommonResult.failed();
    }
}
